<?php
/**
 *
 * @category   babel 
 * @package    BABEL
 * @author     Hannes Magnusson <hannes.magnusson@gmail.com>
 * @copyright  2008 Team babel
 * @license    LGPL
 */


include "includes/babel/prepend_no_gui.php";
include 'classes/babel/Translation_Tasks.php';
include 'classes/babel/TranslationsPoints_Checks.php';
include "includes/babel/ajax_translation.php";

if (isset($_POST["reason"])) {
	$vote = null;
	if (isset($_SESSION["task"]["last_task"])) {
		$vote = @unserialize($_SESSION["task"]["last_task"]);
	}
	if (!($vote instanceof Babel_Translation_Task)) {
		no("Error", "You haven't recieved any tasks yet..");
	}

	$reason = (int)$_POST["reason"];
	if (!isset($CHANGE_REASONS[$reason])) {
		no("Error", "Invalid vote reason($reason)");
	}

	/* TODO:
		* If (in_array(user_id, array(paid_translators))) 
		* then set status=BABEL_TRANSLATE_STATUS_AUTO_APPROVED
		*/
	/* Insert the new translation, and deprecate the old translation */
	$vote->insertTranslation($_SESSION["user"]["user_id"], BABEL_TRANSLATE_STATUS_VOTE);
	$vote->deprecateTranslation($_SESSION["task"]["last_id"]);

	/* Reset the translation number */
	$_SESSION["task"]["skip"] = 0;

	yes("Change submitted, thank you!");
}

no("Error", "Invalid vote reason");

